package com.example.demo.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.example.demo.mapper.CategoryMapper;
import com.example.demo.pojo.Category;
import com.example.demo.pojo.User;
import com.example.demo.pojo.request.CategoryRequest;
import com.example.demo.service.ICategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class CategoryServiceImpl implements ICategoryService {
    
    @Autowired
    private CategoryMapper categoryMapper;
    //查询全部
    @Override
    public List<Category> list() {
        List<Category> userList = categoryMapper.list();
        return userList;
    }

    //分页查询
    @Override
    public PageInfo<Category> page(CategoryRequest categoryRequest) {
        PageHelper.startPage(categoryRequest.getPageNum(),categoryRequest.getPageSize());
        List<Category> userList = categoryMapper.page(categoryRequest);
        return new PageInfo<>(userList);
    }

    //添加数据
    @Override
    public void save(Category Category) {
        Category.setUpdateTime(new Date());
        categoryMapper.save(Category);
    }

    //回写信息
    @Override
    public Category getUser(Integer id) {
        Category category = categoryMapper.getUser(id);
        return category;
    }

    //编辑数据
    @Override
    public void getIDUser(Category Category) {
        Category.setUpdateTime(new Date());
        categoryMapper.getUserByID(Category);
    }

    //删除数据
    @Override
    public void delete(Integer id) {
        categoryMapper.delete(id);
    }

}
